package willevaluate.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.xuegengwang.xuegengwang.R;
import com.makeramen.roundedimageview.RoundedImageView;

import java.util.ArrayList;

import willevaluate.activity.WillCollegeDetail;
import willevaluate.bean.WillListBean;
import view.MyImageLoader;

/**
 * Created by Administrator on 2017/4/18.
 * 志愿评估列表适配器
 */

public class WillListAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<WillListBean> arrayList;
    private String type;//文理科
    private String listType;//冲刺或者保底
    private onMoreClick onMoreClick;
    private String count;
    private String rank;

    public WillListAdapter(Context context, ArrayList<WillListBean> arrayList, String type, String listType, String count, String rank, onMoreClick onMoreClick) {
        this.context = context;
        this.arrayList = arrayList;
        this.type = type;
        this.onMoreClick = onMoreClick;
        this.listType = listType;
        this.count = count;
        this.rank = rank;
    }

    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        MyHolder myHolder;
        if (convertView == null) {
            myHolder = new MyHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.will_list_item, null);
            myHolder.will_list_item_icon = (RoundedImageView) convertView.findViewById(R.id.will_list_item_icon);
            myHolder.will_list_item_school_name = (TextView) convertView.findViewById(R.id.will_list_item_school_name);
            myHolder.will_list_item_school_count = (TextView) convertView.findViewById(R.id.will_list_item_school_count);
            myHolder.will_list_item_school_rank = (TextView) convertView.findViewById(R.id.will_list_item_school_rank);
            myHolder.will_list_item_more = (LinearLayout) convertView.findViewById(R.id.will_list_item_more);
            myHolder.will_list_item_type = (TextView) convertView.findViewById(R.id.will_list_item_type);
            convertView.setTag(myHolder);
        } else {
            myHolder = (MyHolder) convertView.getTag();
        }
        if ("文科".equals(type)) {
            //文科
            myHolder.will_list_item_type.setText("16年文科最低分 : ");
        } else {
            //理科
            myHolder.will_list_item_type.setText("16年理科最低分 : ");
        }

        if (position == (arrayList.size() - 1)) {
            myHolder.will_list_item_more.setVisibility(View.VISIBLE);
            myHolder.will_list_item_more.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    onMoreClick.click();
                }
            });
        }
        convertView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(context, WillCollegeDetail.class);
                i.putExtra("college", arrayList.get(position).getCollege());
                if ("文科".equals(type)) {
                    //文科
                    i.putExtra("type", "art");
                } else {
                    //理科
                    i.putExtra("type", "science");
                }
                i.putExtra("count", count);
                i.putExtra("kind", listType);
                i.putExtra("rank", rank);
                context.startActivity(i);
            }
        });
        myHolder.will_list_item_school_name.setText(arrayList.get(position).getCollege());
        myHolder.will_list_item_school_count.setText(arrayList.get(position).getScore());
        myHolder.will_list_item_school_rank.setText(arrayList.get(position).getRank());
        MyImageLoader.showImage(arrayList.get(position).getIcon(), myHolder.will_list_item_icon);
        return convertView;
    }

    class MyHolder {
        RoundedImageView will_list_item_icon;//校徽
        TextView will_list_item_school_name;//学校名字
        TextView will_list_item_school_count;//分数
        TextView will_list_item_school_rank;//排名
        LinearLayout will_list_item_more;//查看更多
        TextView will_list_item_type;//科目
    }

    public interface onMoreClick {
        void click();
    }
}
